import threading
import _thread
import time
import os
import platform

# 创建一个事件对象
event = threading.Event()

def system_info():
    # 获取操作系统信息
    os_info = platform.platform()
    # 打印操作系统信息
    print(f"操作系统信息: {os_info}")

def terminate_main():
    print("请求终止主进程...")
    event.set()  # 设置事件，通知主进程退出


def main_process():
    try:
        while True:
            # 检查是否需要退出
            if event.is_set():
                print("主进程收到终止信号，正在退出...")
                break
            time.sleep(1)
            print("主进程正在运行...")
    finally:
        print("退出主进程。")


def terminate_main1(x, y):
    print(x, y)
    print("请求终止主进程...")
    _thread.interrupt_main()


def main_process1():
    try:
        while True:
            try:
                pass
            except KeyboardInterrupt:
                print("主进程收到终止信号，正在退出...")
                break
            time.sleep(1)
            print("主进程正在运行...")
    finally:
        print("退出主进程。")


def test1():
    # 创建并启动线程
    thread = threading.Thread(target=terminate_main)
    thread.start()
    # 启动主进程
    main_process()


def test2():
    # 创建并启动线程
    thread = _thread.start_new_thread(terminate_main1, ("x", "y"))
    print(thread)
    # 启动主进程
    main_process1()


if __name__ == "__main__":
    print("shit")
    print(os.name)
    system_info()